package com.molyfun.parents.activity.store;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.BaseActivity;
import com.molyfun.parents.activity.common.attachment.CartViewer;
import com.molyfun.parents.rest.bean.TeacherDetailResponse;
import com.molyfun.parents.utils.Const;
import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/24/16.
 */
public class TeacherProfileActivity extends BaseActivity implements View.OnClickListener{

    @InjectView(R.id.base_title_left)
    ImageView mBack;
    @InjectView(R.id.base_title)
    TextView mBaseTitle;
    @InjectView(R.id.avatar)
    CircleImageView mAvatar;


    @InjectView(R.id.personal_desc)
    TextView mPersonalDesc;
    @InjectView(R.id.personal_speciality)
    TextView mPersonSpeciality;
    @InjectView(R.id.personal_experience)
    TextView mPersonalExperience;
    @InjectView(R.id.personal_train)
    TextView mPersonalTrain;
    @InjectView(R.id.cart_view)
    CartViewer mCartViewer;

    TeacherDetailResponse.TeacherDetailBean mTeacherDetailBean;

    public static void startActivity(Context context, TeacherDetailResponse.TeacherDetailBean teacherDetailBean){
        Intent intent = new Intent();
        intent.setClass(context, TeacherProfileActivity.class);
        intent.putExtra(Const.TEACHER_BEAN, teacherDetailBean);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_teacher_profile);
        ButterKnife.inject(this);

        getSupportActionBar().setTitle("");

        mBack.setOnClickListener(this);

        mTeacherDetailBean = getIntent().getParcelableExtra(Const.TEACHER_BEAN);
        mBaseTitle.setText(mTeacherDetailBean.getUsername());

        if (!TextUtils.isEmpty(mTeacherDetailBean.getHeadimgurl())) {
            Picasso.with(this)
                    .load(mTeacherDetailBean.getHeadimgurl())
                    .config(Bitmap.Config.RGB_565)
                    .placeholder(R.mipmap.ic_header_default)
                    .into(mAvatar);
        } else {
            mAvatar.setImageResource(R.mipmap.ic_header_default);
        }


        mPersonalDesc.setText(mTeacherDetailBean.getResume());
        mPersonSpeciality.setText(mTeacherDetailBean.getSkills());
        mPersonalExperience.setText(mTeacherDetailBean.getExperience());
        mPersonalTrain.setText(mTeacherDetailBean.getTraining());
        mCartViewer.initData(mTeacherDetailBean.getCertList());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.base_title_left:
                finish();
                break;
        }
    }



}
